/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.core.io;

import org.springframework.lang.Nullable;
import org.springframework.util.ResourceUtils;

/**
 *
 * Strategy interface for loading resources (e.. class path or file system  resources).
 * 用来加载资源的策略接口（例如： 类路径/系统文件资源）
 * An {@link org.springframework.context.ApplicationContext} is required to provide this functionality, plus extended {@link org.springframework.core.io.support.ResourcePatternResolver} support.
 * ApplicationContext需要为它提供更多的拓展和功能（Application 会实现这个接口， 也会加上ResourcePatternResolver）
 *
 *
 * <p>{@link DefaultResourceLoader} is a standalone implementation that is
 * usable outside an ApplicationContext, also used by {@link ResourceEditor}.
 *
 * <p>Bean properties of type Resource and Resource array can be populated
 * from Strings when running in an ApplicationContext, using the particular
 * context's resource loading strategy.
 *
 * @author Juergen Hoeller
 * @since 10.03.2004
 * @see Resource
 * @see org.springframework.core.io.support.ResourcePatternResolver
 * @see org.springframework.context.ApplicationContext
 * @see org.springframework.context.ResourceLoaderAware
 */
public interface ResourceLoader {

	/** CLASSPATH_URL_PREFIX = "classpath:". */
	String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX;


	/**
	 * 为指定的资源路径加载资源， 允许多个getInputStream() 调用
	 * allowing for multiple {@link Resource#getInputStream()} calls.
	 * <p>
	 *     <ul>
		   		<li>必须支持标准 URLs, e.g. "file:C:/test.dat".
			  	<li>必须支持classpath pseudo-URLs, e.g. "classpath:test.dat".
			  	<li>应该支持相对文件路径, e.g. "WEB-INF/test.dat".
		 	(This will be implementation-specific, typically provided by an ApplicationContext implementation.)
		  </ul>
	 * <p>
	 * Note that a Resource handle does not imply an existing resource;you need to invoke {@link Resource#exists} to check for existence.
	 * 注意 一个Resource可能不是一个存在的资源，需要调用exists来检查
	 * @param location the resource location
	 * @return a corresponding Resource handle (never {@code null})
	 * @see #CLASSPATH_URL_PREFIX
	 * @see Resource#exists()
	 * @see Resource#getInputStream()
	 */
	Resource getResource(String location);

	/**
	 * Expose the ClassLoader used by this ResourceLoader.
	 * 暴露被这个资源加载器使用的ClassLoader
	 * <p>需要直接访问ClassLoader的客户端可以使用ResourceLoader以统一的方式进行访问, 而不是依赖于线程上下文的ClassLoader.
	 * @return the ClassLoader
	 * (only {@code null} if even the system ClassLoader isn't accessible)
	 * @see org.springframework.util.ClassUtils#getDefaultClassLoader()
	 * @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
	 */
	@Nullable
	ClassLoader getClassLoader();

}
